package com.example.controller;

import com.example.pojo.Category;
import com.example.service.impl.CategoryServiceImpl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CategoryController {

	@Autowired
	private CategoryServiceImpl categoryService;

	/**
	 * 根据父节点id查询商品分类
	 */
	@GetMapping("/list")
	public ResponseEntity<List<Category>> queryCategoryListByPid(@RequestParam("pid") Long pid) {
		// return ResponseEntity.status(HttpStatus.OK).body(null); // 简写以下形式
		return ResponseEntity.ok(categoryService.queryCategoryListByPid(pid));

	}

	/**
	 * 根据id查询商品分类
	 */
	@GetMapping("/list/ids")
	public ResponseEntity<List<Category>> queryCategoryByIds(@RequestParam("ids") List<Long> ids) {
		return ResponseEntity.ok(categoryService.queryByIds(ids));
	}
}
